package org.jwcloud.project.module.zx.common;

public class Resp<T> {

	private String code = "0";
	private String msg = "";
	private T data;
	
	public transient final static String SUCCESS_CODE = "0";
	public transient final static String ERROR_CODE = "-1";
	
	public transient final static String SUCCESS_DESC = "请求成功";
	public transient final static String ERROR_DESC = "请求失败";
	
	public Resp(String errno, String message, T data) {
		super();
		this.code = errno;
		this.msg = message;
		this.data = data;
	}
	
	public Resp(String errno, T data) {
		super();
		this.code = errno;
		this.msg = SUCCESS_DESC;
		this.data = data;
	}

	public static Resp success() {
		return new Resp<String>(SUCCESS_CODE, SUCCESS_DESC, "");
	}
	public static <T> Resp success(T data) {
		return new Resp<T>(SUCCESS_CODE, SUCCESS_DESC, data);
	}
	public static <T> Resp success(String msg, T data) {
		return new Resp<T>(SUCCESS_CODE, msg, data);
	}
	
	public static Resp error() {
		return new Resp<String>(ERROR_CODE, ERROR_DESC, "");
	}
	public static Resp error(String msg) {
		return new Resp(ERROR_CODE, msg, "");
	}
	public static <T> Resp error(String msg, T data) {
		return new Resp<T>(ERROR_CODE, msg, data);
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	
}
